<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    // function _new(ctor, ...args) {
    //   if(typeof ctor !== 'function') return
    //   const obj = {}
    //   const res = ctor.apply(obj, args)
    //   obj.__proto__ = Object.create(ctor.prototype)
    //   if(typeof res === 'object' && typeof res !== 'null') return res
    //   return obj
    // }
    
    function _new(ctor, ...args) {
      if(typeof ctor !== 'function') return
      const obj = {}
      const ret = ctor.call(obj, args)
      obj.__prototype__ = Object.create(ctor.prototype)
      if(typeof ret ==="object" && typeof ret !=='null') return ret
      return obj
    }


    function Parent(age) {
      this.name = 'wjp',
      this.age = age
    }
    Parent.prototype.getName = function() {
      console.log('this.name')
    }
    console.log(_new(Parent, 18))
    console.log(new Parent(18))
  </script>
</body>
</html>